{__NOLAYOUT__}
<layout name="no_nav" />

<style type="text/css">
.form {
	padding-top:10px;
}
.form form label {
	float: left;
	padding-top: 7px;
	padding-right: 8px;
	width: 25%;
	text-align: right;
}
.form .form-item div {
	float: left;
	width: 70%;
}
.form select {
	background-color:#fff;
}
</style>

<div class="form">
  <form method="post" action="saveBank" id="form" class="pd10">
    <div class="form-item clearfix">
      <label>开户银行</label>
      <div>
      	<select name="bankId" id="bankId">{$bank.bankOptions}</select>
      </div>
    </div>
    <!--<div class="form-item clearfix">
      <label>开户支行</label>
      <div>
        <input type="text" name="subbranch" placeholder="请输入收款人开户支行" value="{$bank.subbranch}">
      </div>
    </div>-->
    <div class="form-item clearfix">
      <label>开户姓名</label>
      <div>
        <input type="text" name="accountName" placeholder="请输入收款人姓名" value="{$bank.accountName}">
      </div>
    </div>
    <div class="form-item clearfix">
      <label>手机号</label>
      <div>
        <input type="text" name="tel" placeholder="请输入开户人手机号" value="{$bank.tel}">
      </div>
    </div>
    <div class="form-item clearfix">
      <label>银行卡号</label>
      <div>
        <input type="text" id="account" name="account" placeholder="请输入银行卡号" value="{$bank.account}">
      </div>
    </div>
    <empty name="bank.id">
	    <div class="form-item clearfix">
	      <label></label>
	      <div>
	        <input type="text" id="again-account" placeholder="请再次输入银行卡号" value="">
	      </div>
	    </div>
    </empty>
    <!--<div class="form-item clearfix">
      <label>省份</label>
      <div>
        <select name="province" id="province">{$bank.provinceOptions}</select>
      </div>
    </div>
    <div class="form-item clearfix">
      <label>城市</label>
      <div>
        <select name="city" id="city">{$bank.cityOptions}</select>
      </div>
    </div>-->
    <div class="submit">
     <label></label>
     <input type="hidden" name="id" value="{$bank.id}">
     <button type="submit" class="btn btn-orange mb10">保存收款人信息</button>
    </div>
  </form>
 </div>

  <script type="text/javascript">
   (function(){
	 var sid = {$sid};
     /*var oProvince = document.getElementById( "province" ),
         oCity = document.getElementById( "city" ),
         sid = {$sid};
     oProvince.addEventListener( "change", getCity, false );
     function getCity() {
       var p = this.value;
       $.post( "__CONTROLLER__/getCityPost", {code: p, sid: sid}, function(data){
         oCity.innerHTML = data;
       });
     }*/
     
     var form = document.getElementById ( "form" ),
          formInput = form.getElementsByTagName ( "input" ),
          formSelect = form.getElementsByTagName ( "select" );
       
     form.onsubmit = function() {
       if ( check() ) {
         var data = $("#form").serializeArray();
         data.push({name:'sid', value: sid});
         $.post ( "__CONTROLLER__/saveBank", data, function(data){
           APP.alert(data.msg);
           if (data.error == 0 ) {
        	   window.location = "{$backUrl}"==''?document.referrer:"{$backUrl}";
           }
         });
       }
       return false;
     }
       
     //检查表单
     function check() {
        var check = true;
        for( var i=0,inputSelf; inputSelf=formInput[i]; i++ ) {
          if( inputSelf.getAttribute( "type" )== "hidden" ) { continue; }
          if( trim(inputSelf.value) == "" ) {
        	APP.alert("请填写完整信息");
            inputSelf.value = "";
            check = false;
            return false;
          }
        }
        <empty name="bank.id">
        if ( $("#again-account").val() != $("#account").val() ) {
        	APP.alert("两次输入的银行卡号不一致");
        	$("#again-account").val("");
        	$("#account").val("");
        	check = false;
        }
        </empty>
        
        return check;
     }

     //去除首尾空格
     function trim( str ) {
       return str.replace(/(^\s*)|(\s*$)/g, "");
     }
     
   })()
 </script>